{include file="common/head"/}
<style>
	.sele {
		height: 37px;
		width: 200px;
		border: 1px solid #E6E6E6;
	}
</style>
<div class="admin-main layui-anim layui-anim-upbit">
	<input type="hidden" name="pageId" value="{$pageId}" id='pageId'>
	<fieldset class="layui-elem-field layui-field-title">
		<legend>列表</legend>
	</fieldset>

	<!-- 不需要 -->
	<div class="demoTable">
		<form class="layui-form layui-form-pane">

			<!-- 下拉框 S -->
			<div class="layui-inline">
				<select name="type" id="type" lay-verify="required">
					<option value="">请选择设备类型</option>
					{foreach $deviceTypeList as $key=>$val }
					<option value="{$val.id}" {eq name="$val.id" value="$infoArr['type']" } selected="" {/eq} >{$val.title}</option>
					{/foreach}
				</select>
			</div>
			<!-- 下拉框 E -->

			<!-- 文本框 S -->
			<div class="layui-inline">
				<input type="text" name="title" id="key" ng-model="field.title" placeholder="请输入设备编号" class="layui-input" autocomplete="off">
			</div>
			<!-- 文本框 E -->

			<button class="layui-btn" id="search" type="button" data-type="reload">搜索</button>
			<a href="{:url('index')}" class="layui-btn">显示全部</a>
		</form>
	</div>
	<!-- 不需要 -->


	<table class="layui-table" id="list" lay-filter="list"></table>

</div>

<!-- 需要（编辑的方法名称 主键id 的名称 start-->
<script type="text/html" id="action">
	<a href="{:url('update')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>    <!-- 主键 -->
<!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
</script>
<!-- 需要（编辑的方法名称 主键id 的名称 end-->



<!-- 需要 添加的方法名称 按钮的的title -->
<script type="text/html" id="topBtn">
	<a href="{:url('create')}" class="layui-btn  layui-btn-sm" >添加</a>
</script>
<!-- 需要 添加的方法名称 按钮的的title -->



<script type="text/html" id="pic"> <img src="{{d.pic}}" /></script>

<script type="text/html"
	id="status"><input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="status" {{ d.status == 2 ? "checked" : "" }}></script>

<script type="text/html" id="title"> <a  style="color: #00acc1" href="{:url('update')}?id={{d.id}}">{{d.title}}</a> </script>


{include file="common/foot"/}

<link href="/static/common/css/formSelects-v4.css" rel="stylesheet" />
<script>
	layui.config({
		base: '/static/common/js/' //此处路径请自行处理, 可以使用绝对路径
	}).extend({
		formSelects: 'formSelects-v4'
	});

	layui.use(['table', 'form', 'formSelects'], function () {

		var table = layui.table,
			form = layui.form,
			$ = layui.jquery;

		var pageId = $('#pageId').val();

		var formSelects = layui.formSelects;
		formSelects.btns('serve_type_id', []);
		formSelects.btns('city', []);
		var exportData = '';
		var tableIn = table.render({
			id: 'user',
			elem: '#list',
			url: '{:url("index")}',
			method: 'post',
			toolbar: '#topBtn',
			totalRow: true,
			page: { curr: pageId },
			cols: [
				[

					{
						field: 'id',
						title: 'ID',
						width: 80
					},

					{
						field: 'title',
						title: '设备编号',
						width: 200,
						toolbar: '#title'
					},

					{
						field: 'type',
						title: '设备类型',
						width: 200
					},

					{
						field: 'current_id',
						title: '当前绑定用户',
						width: 200
					},

					{
						field: 'create_time',
						title: '添加时间',
						width: 200
					},

					// {
					// 	field: 'status',
					// 	title: '是否禁用',
					// 	toolbar: '#status',
					// 	width: 200
					// },

					{
						width: 160,
						align: 'center',
						toolbar: '#action'
					}

				]
			],
			done: function (res, curr, count) {
				exportData = res.data; //获取表格中的数据集合。
				// setTimeout(function () {
				// 	if (sessionStorage.getItem('now_page')) {
				// 		sessionStorage.removeItem('now_page');
				// 	}else {
				// 		sessionStorage.setItem('now_page', curr);
				// 	}
				// }, 1000)
			},
		});

		//搜索
		$('#search').on('click', function () {
			var key = $('#key').val();
			var type = $('#type').val();

			tableIn.reload({
				page: {
					page: 1
				},
				where: {
					key: key,
					type: type,
				}
			});
		});

		table.on('tool(list)', function (obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('您确定要删除这条信息吗？', function (index) {
					var loading = layer.load(1, {
						shade: [0.1, '#fff']
					});
					$.post("{:url('remove')}", {
						id: data.id
					}, function (res) { //主键
						layer.close(loading);
						if (res.code === 1) {
							layer.msg(res.msg, {
								time: 1000,
								icon: 1
							});
							tableIn.reload();
						} else {
							layer.msg('操作失败！', {
								time: 1000,
								icon: 2
							});
						}
					});
					layer.close(index);
				});
			}
		});

		form.on('switch(status)', function (obj) {
			loading = layer.load(1, {
				shade: [0.1, '#fff']
			});
			var id = this.value;
			var status = obj.elem.checked === false ? 1 : 2;
			$.post('{:url("setStatus")}', {
				'id': id,
				status: status
			}, function (res) {
				layer.close(loading);
				if (res.code == 1) {
					location.reload();
				} else {
					layer.msg(res.msg, {
						time: 1000,
						icon: 2
					});
					return false;
				}
			})
		});




	});
</script>
</body>

</html>